package com.itheima.springbootmybatisdemo.service.impl;

import com.itheima.springbootmybatisdemo.mapper.LoginMapper;
import com.itheima.springbootmybatisdemo.pojo.Emp;
import com.itheima.springbootmybatisdemo.pojo.EmpDTO;
import com.itheima.springbootmybatisdemo.pojo.EmpVO;
import com.itheima.springbootmybatisdemo.service.LoginService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 15 4月 2025 15:58
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;

    /**
     * 登录
     *
     * @param empDTO
     */
    @Override
    public EmpVO login(EmpDTO empDTO) {
        Emp emp = loginMapper.login(empDTO);
        if (emp == null) {
            throw new RuntimeException("用户名或密码错误");
        }
        EmpVO empVO = new EmpVO();
        BeanUtils.copyProperties(emp, empVO);
        return empVO;
    }
}
